package hos.ui.radio;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import hos.ui.drawable.BackgroundDrawable;
import hos.ui.helper.ShapeHelper;
import hos.ui.helper.TextColorHelper;
import hos.ui.inter.OnClickableListener;

/**
 * <p>Title: RadioButtonView </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2024-06-26 13:34
 */
public class RadioButtonView extends androidx.appcompat.widget.AppCompatRadioButton implements OnClickableListener, BackgroundDrawable<RadioButtonView> {
    public RadioButtonView(Context context) {
        this(context, null);
    }

    public RadioButtonView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.radioButtonStyle);
    }

    public RadioButtonView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        ShapeHelper.DrawableType drawable = ShapeHelper.loadFromAttributes(this, attrs);
        if (drawable != null) {
            setButtonDrawable(null);
            setBackground(drawable.source);
        }
        ColorStateList colorStateList = TextColorHelper.loadFromAttributes(this, attrs);
        if (colorStateList != null) {
            setTextColor(colorStateList);
        }
    }

    public void clickable(boolean isClickable) {
        setClickable(isClickable);
        setEnabled(isClickable);
        setFocusable(isClickable);
    }
}